import path from "path";
import * as fs from 'fs';
import { BuildPlugin } from '../@types';
import { PACKAGE_NAME } from './global';

export const load: BuildPlugin.load = function() {
    const root = Editor.Project.path;
    const dir = path.join(root, 'extensions', PACKAGE_NAME, 'scripts');
    const target = path.join(root, 'preview-template');
    if (!fs.existsSync(target)) fs.mkdirSync(target);
    fs.copyFileSync(path.join(dir, 'fake_cc.js'), path.join(target, 'fake_cc.js'));
    fs.copyFileSync(path.join(dir, 'worker.js'), path.join(target, 'worker.js'));
    fs.copyFileSync(path.join(dir, 'systeminit_preview.js'), path.join(target, 'systeminit.js'));
    console.debug(`${PACKAGE_NAME} load, copied preview worker files`);
};

export const unload: BuildPlugin.load = function() {
    console.debug(`${PACKAGE_NAME} unload`);
};

export const configs: BuildPlugin.Configs = {
    '*': {
        hooks: './hooks',
    },
};